package per.hx.bs.web.sys.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import per.hx.bs.base.BaseController;
import per.hx.bs.base.annotation.BsCLog;
import per.hx.bs.base.domain.PageDO;
import per.hx.bs.base.domain.ReturnDTO;
import per.hx.bs.base.entity.BsLogDO;
import per.hx.bs.web.sys.service.SysLogService;

import java.util.Map;

/**
 * @author HuXing
 * @date 2018/3/26  17:21
 */
@Controller
@RequestMapping(value = "/sys/log")
public class LogController extends BaseController {


    private final
    SysLogService sysLogService;

    @Autowired
    public LogController(SysLogService sysLogService) {
        this.sysLogService = sysLogService;
    }

    @RequiresPermissions("sys:log:log")
    @GetMapping(value = {"/", ""})
    public String log() {
        String prefix = "system/log/";
        return prefix + "log";
    }

    @BsCLog("获取日志列表")
    @RequiresPermissions("sys:log:log")
    @GetMapping("/list")
    @ResponseBody
    public PageDO<BsLogDO> list(@RequestParam Map<String, Object> params) {
        return sysLogService.selectList(params);
    }

    @BsCLog("单个删除日志")
    @RequiresPermissions("sys:log:remove")
    @PostMapping(value = "/remove")
    @ResponseBody
    public ReturnDTO remove(@RequestParam Long id) {
        return ReturnDTO.check(sysLogService.delete(id));
    }

    @BsCLog("批量删除日志")
    @RequiresPermissions("sys:log:remove")
    @PostMapping(value = "/batchRemove")
    @ResponseBody
    public ReturnDTO batchRemove(@RequestParam("ids[]") Long[] ids) {
        return ReturnDTO.check(sysLogService.batchDelete(ids));
    }

    @BsCLog("清空所有日志文件")
    @RequiresPermissions("sys:log:cleanAll")
    @GetMapping(value = "/cleanAll")
    @ResponseBody
    public ReturnDTO cleanAll() {
        return ReturnDTO.check(sysLogService.cleanAll());
    }
}
